// pages/musuc/music.js
 
const innerAudioContext = wx.createInnerAudioContext()
// innerAudioContext.autoplay = true
innerAudioContext.src = 'https://aqqmusic.tc.qq.com/amobile.music.tc.qq.com/C400002VHqVq4VbH4v.m4a?guid=50142748&vkey=D0FE0B9587D55100AA5B6FB9A348423ABCACA23484E91C47DCAD2F664ADCAC0A3486CEF1E79553FB42B42C37D18B6500C0480B0DD15A718A&uin=28532357&fromtag=123032'
innerAudioContext.onPlay(() => {
  console.log('开始播放')
})
innerAudioContext.onStop(()=>{
  console.log('结束')
})
innerAudioContext.onError((res) => {
  console.log(res.errMsg)
  console.log(res.errCode)
})
var timer
Page({
    
  /**
   * 页面的初始数据
   */
  data: {
    isplay: false,
    tran:"trans",
    rocate:"paused"
  },
  play(){
    if(this.data.isplay == false){
      this.setData({
        isplay: true 
      })
      this.setData({
        rocate:"running"
      })
      innerAudioContext.play()
      
    }else{
      this.setData({
        isplay: false 
      })
      this.setData({
        rocate:"paused"
      })
      innerAudioContext.pause()
      console.log(innerAudioContext.currentTime)
      console.log(innerAudioContext.duration)
    }
    timer= setInterval(()=>{
      if(innerAudioContext.currentTime == innerAudioContext.duration
        && innerAudioContext.duration!=0){
        this.setData({
          rocate:"paused"
        })
        clearInterval(timer)
      }
    },30)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
 
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
 
  }
})